package com.macro.mall.service.impl;

import com.github.pagehelper.PageHelper;
import com.macro.mall.dto.BmsNarratorThemeApplicantDetail;
import com.macro.mall.dto.BmsNarratorThemeApplicantParam;
import com.macro.mall.mapper.BmsNarratorThemeApplicantMapper;
import com.macro.mall.model.BmsNarratorThemeApplicant;
import com.macro.mall.model.BmsNarratorThemeApplicantExample;
import com.macro.mall.service.BmsNarratorThemeApplicantService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

@Service
public class BmsNarratorThemeApplicantServiceImpl implements BmsNarratorThemeApplicantService {

    @Autowired
    private BmsNarratorThemeApplicantMapper bmsNarratorThemeApplicantMapper;

    @Override
    public List<BmsNarratorThemeApplicant> getList(BmsNarratorThemeApplicantParam bmsNarratorThemeApplicantParam) {
        Integer pageNum = bmsNarratorThemeApplicantParam.getPageNum();
        Integer pageSize = bmsNarratorThemeApplicantParam.getPageSize();
        if (Objects.nonNull(pageNum) && Objects.nonNull(pageSize)) {
            PageHelper.startPage(pageNum, pageSize);
        }
        BmsNarratorThemeApplicantExample example = new BmsNarratorThemeApplicantExample();
        BmsNarratorThemeApplicantExample.Criteria criteria = example.createCriteria();
        criteria.andIsDeleteEqualTo((byte) 0);
        if (Objects.nonNull(bmsNarratorThemeApplicantParam.getNarratorThemeId())) {
            criteria.andNarratorThemeIdEqualTo(bmsNarratorThemeApplicantParam.getNarratorThemeId());
        }
        if (StringUtils.isNotBlank(bmsNarratorThemeApplicantParam.getUserName())) {
            criteria.andUserNameLike("%" + bmsNarratorThemeApplicantParam.getUserName() + "%");
        }
        if (StringUtils.isNotBlank(bmsNarratorThemeApplicantParam.getUserPhone())) {
            criteria.andUserPhoneLike("%" + bmsNarratorThemeApplicantParam.getUserPhone() + "%");
        }
        if (Objects.nonNull(bmsNarratorThemeApplicantParam.getUserIdType())) {
            criteria.andUserIdTypeEqualTo(bmsNarratorThemeApplicantParam.getUserIdType());
        }
        if (StringUtils.isNotBlank(bmsNarratorThemeApplicantParam.getUserIdCard())) {
            criteria.andUserIdCardLike("%" + bmsNarratorThemeApplicantParam.getUserIdCard() + "%");
        }
        if (Objects.nonNull(bmsNarratorThemeApplicantParam.getApplicationTime())) {
            criteria.andApplicationTimeGreaterThanOrEqualTo(bmsNarratorThemeApplicantParam.getApplicationTime());
        }
        if (StringUtils.isNotBlank(bmsNarratorThemeApplicantParam.getStatus())) {
            criteria.andStatusEqualTo(bmsNarratorThemeApplicantParam.getStatus());
        }

        List<BmsNarratorThemeApplicant> list = bmsNarratorThemeApplicantMapper.selectByExample(example);
        return list;
    }

    @Override
    public BmsNarratorThemeApplicantDetail getItem(Long id) {
        BmsNarratorThemeApplicant bmsNarratorThemeApplicant = bmsNarratorThemeApplicantMapper.selectByPrimaryKey(id);
        BmsNarratorThemeApplicantDetail detail = new BmsNarratorThemeApplicantDetail();
        BeanUtils.copyProperties(bmsNarratorThemeApplicant, detail);
        return detail;
    }
    
    @Override
    public List<BmsNarratorThemeApplicant> getExportList(BmsNarratorThemeApplicantParam bmsNarratorThemeApplicantParam) {
        BmsNarratorThemeApplicantExample example = new BmsNarratorThemeApplicantExample();
        BmsNarratorThemeApplicantExample.Criteria criteria = example.createCriteria();
        criteria.andIsDeleteEqualTo((byte) 0);
        if (Objects.nonNull(bmsNarratorThemeApplicantParam.getNarratorThemeId())) {
            criteria.andNarratorThemeIdEqualTo(bmsNarratorThemeApplicantParam.getNarratorThemeId());
        }
        if (StringUtils.isNotBlank(bmsNarratorThemeApplicantParam.getUserName())) {
            criteria.andUserNameLike("%" + bmsNarratorThemeApplicantParam.getUserName() + "%");
        }
        if (StringUtils.isNotBlank(bmsNarratorThemeApplicantParam.getUserPhone())) {
            criteria.andUserPhoneLike("%" + bmsNarratorThemeApplicantParam.getUserPhone() + "%");
        }
        if (Objects.nonNull(bmsNarratorThemeApplicantParam.getUserIdType())) {
            criteria.andUserIdTypeEqualTo(bmsNarratorThemeApplicantParam.getUserIdType());
        }
        if (StringUtils.isNotBlank(bmsNarratorThemeApplicantParam.getUserIdCard())) {
            criteria.andUserIdCardLike("%" + bmsNarratorThemeApplicantParam.getUserIdCard() + "%");
        }
        if (Objects.nonNull(bmsNarratorThemeApplicantParam.getApplicationTime())) {
            criteria.andApplicationTimeGreaterThanOrEqualTo(bmsNarratorThemeApplicantParam.getApplicationTime());
        }
        if (StringUtils.isNotBlank(bmsNarratorThemeApplicantParam.getStatus())) {
            criteria.andStatusEqualTo(bmsNarratorThemeApplicantParam.getStatus());
        }

        List<BmsNarratorThemeApplicant> list = bmsNarratorThemeApplicantMapper.selectByExample(example);
        return list;
    }
}
